<template>
  <div class="article">
    <!-- 按钮 -->
    <div class="btns">
      <el-form label="主题" size="small" inline style="text-align: center">
        <el-form-item label="主题" size="small" inline>
          <el-input v-model="param.title" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="类别ID" size="small" inline>
          <el-input v-model="param.categoryId" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
           plain
            type="primary"
            size="small"
            icon="el-icon-search" 
            @click="loadArticles"
            >搜索</el-button
          >
        </el-form-item>
      </el-form>
      <el-button
        round
        plain
        style="float: right"
        type="primary"
        size="small"
        icon="el-icon-edit"
        @click="toAddHandler"
        >新增</el-button
      >
           <el-button
        round
        plain
        style="float: right"
        type="warning"
        size="small"
        icon="el-icon-edit"
        @click="downloadHandler"
        >导出</el-button
      >
    </div>
    <el-alert center title="文章模块" type="info" effect="dark"> </el-alert>   <el-divider><i class="el-icon-mobile-phone"></i></el-divider>
    <!-- /按钮 -->
    <!-- {{applications}} -->
    <!-- 表格 -->
    <el-table size="small" :data="articles">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column
        label="主题"
        prop="title"
        align="center"
      ></el-table-column>
      <el-table-column
        label="简介"
        prop="brief"
        align="center"
      ></el-table-column>
      <el-table-column
        label="文章"
        prop="content"
        align="center"
      width="600px"></el-table-column>
      <el-table-column
        label="出版时间"
        prop="publishTime"
        align="center"
        sortable
      ></el-table-column>
      <el-table-column
        label="阅读时间"
        prop="readTimes"
        align="center"
          sortable
      ></el-table-column>
      <el-table-column
        label="状态"
        prop="status"
        align="center"
      ></el-table-column>
      <el-table-column
        label="thumpUp"
        prop="thumpUp"
        align="center"
      ></el-table-column>
      <el-table-column
        label="封面"
        prop="cover"
        align="center"
      ></el-table-column>
      <el-table-column
        label="作者ID"
        prop="authorId"
        align="center"
      ></el-table-column>
      <el-table-column
        label="类别ID"
        prop="categoryId"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="200px" align="center">
        <template slot-scope="scope">
          <el-button round plain type="primary" size="mini" icon="el-icon-edit" @click="editHandler(scope.row)"
            >修改</el-button
          >
          <el-button
          round
            plain
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="deleteHandler(scope.row)"
            >删除</el-button
          >
          
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>

<script>
import { del, get, post } from "@/utils/request";
export default {
  // 页面数据
  // 页面数据
  data() {
    return {
      param: {
        name:""
      },
      articles: [],
    };
  },
  // 页面渲染的时候会调用的函数
  created() {
    this.loadArticles();
    console.log(this.$router);
  },
  // 所有的方法
  methods: {
    downloadHandler(){
      window.location.href="http://39.106.31.187:8888/article/download?name="+this.param.name;
    },
    editHandler(row) {
      this.$router.push({
        path: "/article/articleCreate",
        query: row,
      });
    },
    deleteHandler(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://39.106.31.187:8888/article/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadArticles();
        });
      });
    },
    toAddHandler() {
      this.$router.push("/article/articleCreate");
    },
    loadArticles() {
      let url = "http://39.106.31.187:8888/article/query";
      get(url, this.param).then((resp) => {
        this.articles = resp.data;
      });
    },
  },
};
</script>

<style scoped>
</style>
